import os
from xml.dom.minidom import Document


# 创建渠道xml文件
def write_channel_xml(filename, tag_name, channel):
    if os.path.exists(filename):
        os.remove(filename)

    # 创建doc
    doc = Document()
    # 创建根节点
    root = doc.createElement(tag_name)
    doc.appendChild(root)

    channel_text = doc.createTextNode(channel)
    root.appendChild(channel_text)

    with open(filename, 'wb') as f:
        f.write(doc.toprettyxml(indent='\t', encoding='utf-8'))
